<template>
  <div class="ele-body">
    <a-card :bordered="false" title="货品信息">
      <a-form
        :label-col="{ md: { span: 12 }, sm: { span: 12 }, xs: { span: 24 } }"
        :wrapper-col="{ md: { span: 12 }, sm: { span: 12 }, xs: { span: 24 } }"
      >
        <a-row :gutter="24">
          <a-col
            :md="6"
            :sm="12"
            :xs="12"
            v-for="(item, index) in firstArr"
            :key="index"
          >
            <selectinp
              ref="selectinpRef"
              v-model:value="form[item.value]"
              :dataValue="form[item.value]"
              :itemData="item"
              :validateInfos="validateInfos"
            />
          </a-col>
          <a-col
            v-show="searchExpand"
            :md="6"
            :sm="12"
            :xs="12"
            v-for="(item, index) in lastArr"
            :key="index"
          >
            <selectinp
              ref="selectinpRef"
              v-model:value="form[item.value]"
              :dataValue="form[item.value]"
              :itemData="item"
              :thumb_url="thumb_url"
              :validateInfos="validateInfos"
              @getImg="getImg"
              @getImgUrl="getImgUrl"
              @getSeriesStyle="getSeriesStyleList"
            />
          </a-col>
          <a-col :md="6" :sm="12" :xs="12" :offset="18">
            <a-form-item label="" class="text-right">
              <a @click="toggleExpand">
                <span v-if="searchExpand">
                  收起
                  <up-outlined class="ele-text-small" />
                </span>
                <span v-else>
                  更多信息
                  <down-outlined class="ele-text-small" />
                </span>
              </a>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
      <div>
        <div
          class="fs-16 fw-bolder margin-bottom-15"
          v-if="mainStone.tableData.length > 0"
          >主石信息</div
        >
        <div v-if="mainStone.tableData.length > 0">
          <vxe-table
            border
            ref="xTable1"
            :edit-config="{ trigger: 'click', mode: 'cell', showIcon: false }"
            :data="mainStone.tableData"
          >
            <vxe-column type="seq" title="NO" width="60" fixed="left" />
            <vxe-column
              ref="table1111"
              v-for="config in mainStone.tableColumn"
              :key="config.key"
              :field="config.field"
              :title="config.title"
              :fixed="config.fixed"
              :width="config.width"
              :params="{ type: config.inputType, options: config.options }"
              :edit-render="{}"
            >
              <template #default="{ column, row }">
                <span
                  v-if="
                    column.params.type == 'select' ||
                    column.params.type == 'selectajax'
                  "
                  >{{
                    productSpec(column.params.options, row[config.field])
                  }}</span
                >
                <span v-else>{{ row[config.field] }}</span>
              </template>
              <template #edit="{ column, row }">
                <vxe-select
                  v-if="
                    column.params.type == 'select' ||
                    column.params.type == 'selectajax'
                  "
                  v-model="row[config.field]"
                  placeholder="请选择"
                  transfer
				  clearable
                >
                  <vxe-option
                    v-for="item in column.params.options"
                    :key="item.value"
                    :value="item.value"
                    :label="item.label"
                  />
                </vxe-select>
                <vxe-input
                  v-else
                  v-model="row[config.field]"
                  type="text"
                  placeholder="请输入"
                />
              </template>
            </vxe-column>
          </vxe-table>
          <vxe-toolbar>
            <template #buttons>
              <vxe-button @click="insertEvent1(-1)" v-show="length1 < 2"
                >新增</vxe-button
              >
            </template>
          </vxe-toolbar>
        </div>
      </div>
      <div>
        <div
          class="fs-16 fw-bolder margin-bottom-15"
          v-if="viceStone.tableData.length > 0"
          >副石信息</div
        >
        <div v-if="viceStone.tableData.length > 0">
          <vxe-table
            border
            ref="xTable2"
            :edit-config="{ trigger: 'click', mode: 'cell', showIcon: false }"
            :data="viceStone.tableData"
          >
            <vxe-column type="seq" title="NO" width="60" fixed="left" />
            <vxe-column
              ref="table2222"
              v-for="config in viceStone.tableColumn"
              :key="config.key"
              :field="config.field"
              :title="config.title"
              :fixed="config.fixed"
              :width="config.width"
              :params="{ type: config.inputType, options: config.options }"
              :edit-render="{}"
            >
              <template #default="{ column, row }">
                <span
                  v-if="
                    column.params.type == 'select' ||
                    column.params.type == 'selectajax'
                  "
                  >{{
                    productSpec(column.params.options, row[config.field])
                  }}</span
                >
                <span v-else>{{ row[config.field] }}</span>
              </template>
              <template #edit="{ column, row }">
                <vxe-select
                  v-if="
                    column.params.type == 'select' ||
                    column.params.type == 'selectajax'
                  "
                  v-model="row[config.field]"
                  placeholder="请选择"
                  transfer
				  clearable
                >
                  <vxe-option
                    v-for="item in column.params.options"
                    :key="item.value"
                    :value="item.value"
                    :label="item.label"
                  />
                </vxe-select>
                <vxe-input
                  v-else
                  v-model="row[config.field]"
                  type="text"
                  placeholder="请输入"
                />
              </template>
            </vxe-column>
          </vxe-table>
          <vxe-toolbar>
            <template #buttons>
              <vxe-button @click="insertEvent2(-1)" v-show="length2 < 3"
                >新增</vxe-button
              >
            </template>
          </vxe-toolbar>
        </div>
      </div>
    </a-card>
    <div style="width: 100%; height: 100px"></div>
    <!-- 底部工具栏 -->
    <div class="ele-bottom-tool">
      <div class="ele-bottom-tool-actions">
        <a-space size="large">
          <a-button type="primary" :loading="loading" @click="save()"
            >保存</a-button
          >
          <a-button
            type="default"
            class="btn"
            :loading="loading"
            @click="finishPageTab()"
            >取消</a-button
          >
        </a-space>
      </div>
    </div>
  </div>
</template>

<script setup>
  import {
    ref,
    reactive,
    unref,
    onMounted,
    defineComponent,
    computed
  } from 'vue';
  import {
    DownOutlined,
    UpOutlined,
    PlusOutlined,
    LoadingOutlined
  } from '@ant-design/icons-vue';
  import { useRouter } from 'vue-router';
  import { message, Modal, Form } from 'ant-design-vue';
  import { finishPageTab } from '@/utils/page-tab-util';
  import { uploadUrl } from '@/config/setting';
  import { isEmptyFn } from '@/utils/objIsEmpty.js';
  import selectinp from '@/components/zbInput/huopinSelectInput.vue';
  import {
    get_broad_class_list,
    get_subclass_list,
    get_quality_list,
    get_style_list,
    get_supplier_list,
    get_supplier_style_list,
    get_series_list,
    get_series_style_list,
    get_gift_list,
    get_technology_list,
    get_price_category_list,
    get_gem_category_list,
    get_finance_list,
    get_gem_attribute_list,
    add_goods,
    goods_detail,
    get_column_templete_list,
    get_store_brand_list,
    get_brand_list,
    get_classes_list,
    get_metal_color_list,
    get_labor_category_list,
    get_stone_weight_list,
    edit_goods
  } from '@/api/jewelry/receipts_purchase';
  import { forIn } from 'lodash-es';

  const useForm = Form.useForm;
  const loading = ref(false);
  const { currentRoute, push } = useRouter();
  const { query } = unref(currentRoute);
  console.log('query:', query);

  // 是否展开
  const searchExpand = ref(false);

  const arrParmas = ref([]);
  const form = reactive({});
  const rules = reactive({});
  const thumb_url = ref(null);
  // 默认显示的
  const firstArr = ref(null);
  // 默认隐藏的
  const lastArr = ref(null);
  //主石
  const mainStone = reactive({
    tableColumn: [],
    tableData: []
  });
  //副石
  const viceStone = reactive({
    tableColumn: [],
    tableData: []
  });
  onMounted(async () => {
    //货品信息
    await get_column_templete_list({
      filters: {
        receipts_type: 1,
        goods_category_code: query.goods_category_code,
        type: 'sku_info'
      }
    }).then(async (res) => {
      arrParmas.value = [];
      /* await res.row_list.forEach(async (item, index) => {
        if (item.column_type != 'count') {
          await arrParmas.value.push({
            type: item.column_type,
            label: item.name,
            value: item.column,
            params: item.params,
            require: item.require,
            disabled: item.column == 'num' ? true : false
          });
          if (
            item.column == 'retail_type' ||
            item.column == 'purchase_labour_amount'
          ) {
            arrParmas.value[index].options = item.params;
          }
          if (item.column == 'num') {
            form[item.column] = 1;
          } else {
            form[item.column] = '';
          }
          rules[item.column] = [
            {
              required: item.require == 1 ? true : false,
              message:
                item.column_type === 'select' ||
                item.column_type === 'selectajax' ||
                item.column_type === 'selectajaxlike'
                  ? `请选择${item.name}`
                  : `请输入${item.name}`,
              trigger: 'change'
            }
          ];
        }
      }); */
      let list = [];
      await res.row_list.forEach((item, index) => {
        if (item.column_type != 'count') {
          list.push(item);
        }
      });
      await list.forEach(async (item, index) => {
        if (item.column_type != 'count') {
          list.push(item);
        }
        await arrParmas.value.push({
          type: item.column_type,
          label: item.name,
          value: item.column,
          params: item.params ? item.params : '',
          require: item.require,
          disabled: false
        });
        if (item.column == 'retail_type' || item.column == 'labor_type') {
          arrParmas.value[index].options = item.params;
        }
        if (item.column == 'bar_code' || item.column == 'num') {
          arrParmas.value[index].disabled = true;
        }
        if (item.column == 'num') {
          form[item.column] = 1;
        } else {
          form[item.column] = '';
        }
        rules[item.column] = [
          {
            required: item.require == 1 ? true : false,
            message:
              item.column_type == 'select' ||
              item.column_type == 'selectajax' ||
              item.column_type == 'selectajaxlike' ||
              item.column_type == 'image'
                ? `请选择${item.name}`
                : `请输入${item.name}`,
            trigger: 'change'
          }
        ];
      });
      console.log('arrParmas.value', arrParmas.value);
      firstArr.value = arrParmas.value.slice(0, 20);
      lastArr.value = arrParmas.value.slice(20, arrParmas.value.length);
    });
    //主石信息
    mainStone.tableColumn = [];
    await get_column_templete_list({
      filters: {
        receipts_type: 1,
        goods_category_code: query.goods_category_code,
        type: 'main_stone'
      }
    }).then(async (res) => {
      let obj = {};
      await res.row_list.forEach((item, index) => {
        mainStone.tableColumn.push({
          key: index,
          type: item.column_type,
          inputType: item.column_type,
          title: item.name,
          field: item.column,
          require: item.require,
          width: 150
        });
        obj[item.column] = '';
        //obj.type = 1;
      });
      mainStone.tableData.push(obj);

      console.log('mainStone.tableColumn', mainStone.tableColumn);
    });
    await getDetail();
    //副石信息
    viceStone.tableColumn = [];
    await get_column_templete_list({
      filters: {
        receipts_type: 1,
        goods_category_code: query.goods_category_code,
        type: 'vice_stone'
      }
    }).then(async (res) => {
      let obj = {};
      await res.row_list.forEach((item, index) => {
        viceStone.tableColumn.push({
          key: index,
          type: item.column_type,
          inputType: item.column_type,
          title: item.name,
          field: item.column,
          require: item.require,
          width: 150
        });
        obj[item.column] = '';
        //obj.type = 2;
      });
      viceStone.tableData.push(obj);
    });
    //货品大类
    await get_broad_class_list({ page: 1, page_size: 9999 }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      arrParmas.value.forEach((item) => {
        if (item.value == 'class_code') {
          item.options = options;
        }
      });
    });
    //货品小类
    await get_subclass_list({ page: 1, page_size: 9999 }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      arrParmas.value.forEach((item) => {
        if (item.value == 'subclass_code') {
          item.options = options;
        }
      });
    });
    //成色
    await get_quality_list({ page: 1, page_size: 9999 }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      arrParmas.value.forEach((item) => {
        if (item.value == 'quality_code') {
          item.options = options;
        }
      });
    });
    //门店品牌
    await get_store_brand_list({ page: 1, page_size: 9999 }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      arrParmas.value.forEach((item) => {
        if (item.value == 'store_brand_code') {
          item.options = options;
        }
      });
    });
    //经营品牌
    await get_brand_list({ page: 1, page_size: 9999 }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      arrParmas.value.forEach((item) => {
        if (item.value == 'brand_code') {
          item.options = options;
        }
      });
    });
    //系列名称
    await get_series_list({ page: 1, page_size: 9999 }).then(async (res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      arrParmas.value.forEach((item) => {
        if (item.value == 'series_code') {
          item.options = options;
        }
      });
      await getSeriesStyle(form.series_code);
    });
    /* //系列款式
    await get_series_style_list({ page: 1, page_size: 9999 }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      arrParmas.value.forEach((item) => {
        if (item.value == 'series_style_code') {
          item.options = options;
        }
      });
    }); */

    //赠品类型
    await get_gift_list({ page: 1, page_size: 9999 }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      arrParmas.value.forEach((item) => {
        if (item.value == 'gift_code') {
          item.options = options;
        }
      });
    });
    //工艺类型
    await get_technology_list({ page: 1, page_size: 9999 }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      arrParmas.value.forEach((item) => {
        if (item.value == 'technology_code') {
          item.options = options;
        }
      });
    });
    //价格类型
    await get_price_category_list({ page: 1, page_size: 9999 }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      arrParmas.value.forEach((item) => {
        if (item.value == 'price_category_code') {
          item.options = options;
        }
      });
    });
    //宝石类别
    await get_gem_category_list({ page: 1, page_size: 9999 }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      arrParmas.value.forEach((item) => {
        if (item.value == 'gem_category_code') {
          item.options = options;
        }
      });
    });
    //货品品类
    await get_classes_list({ page: 1, page_size: 9999 }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      arrParmas.value.forEach((item) => {
        if (item.value == 'classes_code') {
          item.options = options;
        }
      });
    });
    //贵金属颜色
    await get_metal_color_list({ page: 1, page_size: 9999 }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      arrParmas.value.forEach((item) => {
        if (item.value == 'metal_color_code') {
          item.options = options;
        }
      });
    });
    //工费类型
    await get_labor_category_list({ page: 1, page_size: 9999 }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      arrParmas.value.forEach((item) => {
        if (item.value == 'labor_category_code') {
          item.options = options;
        }
      });
    });
    //财务类型
    await get_finance_list({ page: 1, page_size: 9999 }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      arrParmas.value.forEach((item) => {
        if (item.value == 'finance_code') {
          item.options = options;
        }
      });
    });
    //宝石属性  颜色
    await get_gem_attribute_list({
      page: 1,
      page_size: 9999,
      type: 'color'
    }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      arrParmas.value.forEach((item) => {
        if (
          item.value == 'cert_first_color' ||
          item.value == 'cert_second_color'
        ) {
          item.options = options;
        }
      });
      mainStone.tableColumn.forEach((item) => {
        if (item.field == 'color') {
          item.options = options;
        }
      });
      viceStone.tableColumn.forEach((item) => {
        if (item.field == 'color') {
          item.options = options;
        }
      });
    });
    //宝石属性  切工
    await get_gem_attribute_list({
      page: 1,
      page_size: 9999,
      type: 'cut'
    }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      arrParmas.value.forEach((item) => {
        if (item.value == 'cert_first_cut' || item.value == 'cert_second_cut') {
          item.options = options;
        }
      });
      mainStone.tableColumn.forEach((item) => {
        if (item.field == 'cut') {
          item.options = options;
        }
      });
      viceStone.tableColumn.forEach((item) => {
        if (item.field == 'cut') {
          item.options = options;
        }
      });
    });
    //宝石属性  形状
    await get_gem_attribute_list({
      page: 1,
      page_size: 9999,
      type: 'form'
    }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      arrParmas.value.forEach((item) => {
        if (
          item.value == 'cert_first_form' ||
          item.value == 'cert_second_form'
        ) {
          item.options = options;
        }
      });
      mainStone.tableColumn.forEach((item) => {
        if (item.field == 'form') {
          item.options = options;
        }
      });
      viceStone.tableColumn.forEach((item) => {
        if (item.field == 'form') {
          item.options = options;
        }
      });
    });
    //宝石属性  净度
    await get_gem_attribute_list({
      page: 1,
      page_size: 9999,
      type: 'neatness'
    }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      arrParmas.value.forEach((item) => {
        if (
          item.value == 'cert_first_neatness' ||
          item.value == 'cert_second_neatness'
        ) {
          item.options = options;
        }
      });
      mainStone.tableColumn.forEach((item) => {
        if (item.field == 'neatness') {
          item.options = options;
        }
      });
      viceStone.tableColumn.forEach((item) => {
        if (item.field == 'neatness') {
          item.options = options;
        }
      });
    });
    //宝石属性  抛光
    await get_gem_attribute_list({
      page: 1,
      page_size: 9999,
      type: 'buffing'
    }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      mainStone.tableColumn.forEach((item) => {
        if (item.field == 'buffing') {
          item.options = options;
        }
      });
      viceStone.tableColumn.forEach((item) => {
        if (item.field == 'buffing') {
          item.options = options;
        }
      });
    });
    //宝石属性  对称
    await get_gem_attribute_list({
      page: 1,
      page_size: 9999,
      type: 'symmetric'
    }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      mainStone.tableColumn.forEach((item) => {
        if (item.field == 'symmetric') {
          item.options = options;
        }
      });
      viceStone.tableColumn.forEach((item) => {
        if (item.field == 'symmetric') {
          item.options = options;
        }
      });
    });
    //宝石属性  荧光
    await get_gem_attribute_list({
      page: 1,
      page_size: 9999,
      type: 'fluorescence'
    }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      mainStone.tableColumn.forEach((item) => {
        if (item.field == 'fluorescence') {
          item.options = options;
        }
      });
      viceStone.tableColumn.forEach((item) => {
        if (item.field == 'fluorescence') {
          item.options = options;
        }
      });
    });
    //宝石属性  石重范围
    await get_stone_weight_list({ page: 1, page_size: 9999 }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      mainStone.tableColumn.forEach((item) => {
        if (item.field == 'stone_weight_code') {
          item.options = options;
        }
      });
      viceStone.tableColumn.forEach((item) => {
        if (item.field == 'stone_weight_code') {
          item.options = options;
        }
      });
    });
    //供应商
    await get_supplier_list({
      page: 1,
      page_size: 99999,
      type: 'neatness'
    }).then((res) => {
      let options = [];
      res.list.map((item) => {
        options.push({
          value: String(item.code),
          label: item.name
        });
      });
      arrParmas.value.forEach((item) => {
        if (item.value == 'supplier_code') {
          item.options = options;
        }
      });
    });
  });

  const getDetail = () => {
    goods_detail({ goods_code: query.goods_code }).then(async (res) => {
      let obj = {};
      await res.goods_info.sku_info.forEach((item, index) => {
        if (item.column == 'labor_type') {
          item.value = item.value.toString();
        }
        obj[item.column] = item.value;
      });
      await Object.keys(form).forEach((key) => {
        form[key] = obj[key] ? obj[key] : '';
      });
      thumb_url.value =
        res.goods_info.thumb_url == 0 ? '' : res.goods_info.thumb_url;
      mainStone.tableData = res.goods_info.master_gem.row_list;
      viceStone.tableData = res.goods_info.vice_gem.row_list;
    });
  };
  const getSeriesStyleList = (val) => {
    //每次系列名称修改， 系列款式联动
    form.series_style_code = '';
    getSeriesStyle(val);
  };
  //系列款式
  const getSeriesStyle = (val) => {
    get_series_style_list({ page: 1, page_size: 9999, series_code: val }).then(
      (res) => {
        let options = [];
        res.list.map((item) => {
          options.push({
            value: String(item.code),
            label: item.name
          });
        });
        arrParmas.value.forEach((item) => {
          if (item.value == 'series_style_code') {
            item.options = options;
          }
        });
      }
    );
  };

  //主石
  const xTable1 = ref(null);
  const length1 = ref(1);
  const insertEvent1 = async (row) => {
    length1.value++;
    const $table = xTable1.value;
    const record = {
      type: 1
    };
    const { row: newRow } = await $table.insertAt(record, row);
    await $table.setEditCell(newRow, 'name');
  };
  const getInsertEvent1 = () => {
    const $table = xTable1.value;
    const insertRecords = $table.getInsertRecords();
    mainStone.tableData = mainStone.tableData.concat(
      JSON.parse(JSON.stringify(insertRecords))
    );
  };
  //副石
  const xTable2 = ref(null);
  const length2 = ref(1);
  const insertEvent2 = async (row) => {
    length2.value++;
    const $table = xTable2.value;
    const record = {
      type: 2
    };
    const { row: newRow } = await $table.insertAt(record, row);
    await $table.setEditCell(newRow, 'name');
  };
  const getInsertEvent2 = () => {
    const $table = xTable2.value;
    const insertRecords = $table.getInsertRecords();
    viceStone.tableData = viceStone.tableData.concat(
      JSON.parse(JSON.stringify(insertRecords))
    );
  };

  const toggleExpand = () => {
    searchExpand.value = !searchExpand.value;
  };

  //根据value寻找label， 用于回显
  const productSpec = (list, code) => {
    //console.log('）））', list, code);
    if (list && list.length > 0) {
      const item = list.find((item) => item.value === code);
      return item ? item.label : code;
    }
  };

  const getImg = (data) => {
    console.log('===', data);
    Object.assign(form, data);
  };
  const getImgUrl = (data) => {
    console.log('&&&', data);
    thumb_url.value = data.url;
  };

  const { validate, validateInfos } = useForm(form, rules);

  const save = async () => {
    validate()
      .then(async () => {
        if (mainStone.tableData.length > 0) {
          await getInsertEvent1();
        }
        if (viceStone.tableData.length > 0) {
          await getInsertEvent2();
        }
        let mainTableData = [];
        let viceTableData = [];
        //主石去空
        mainStone.tableData.forEach((item, index) => {
          if (!isEmptyFn(item)) {
            item.type = 1;
            item.sub_type = index + 1;
            mainTableData.push(item);
          }
        });
        //副石去空
        viceStone.tableData.forEach((item, index) => {
          if (!isEmptyFn(item)) {
            item.type = 2;
            item.sub_type = index + 1;
            viceTableData.push(item);
          }
        });
        form.gem_item = [];
        form.gem_item = form.gem_item
          .concat(mainTableData)
          .concat(viceTableData);
        form.code = query.code;
        form.goods_code = query.goods_code;
        console.log('form', form);
        edit_goods(form)
          .then((res) => {
            message.success(res.msg);
          })
          .catch((e) => {
            message.error(e);
          });
      })
      .catch((e) => {
        message.error(e);
        console.log(222, e);
      });
  };
</script>
